//
//  CNMutableContact+Extension.m
//  CreditAddressBook
//
//  Created by Lee on 15/9/23.
//  Copyright © 2015年 Lee. All rights reserved.
//

#if IS_IOS9
#import "CNMutableContact+Extension.h"
#import "CYABTool.h"

@implementation CNMutableContact (Extension)

- (void)setPhones:(NSArray *)phones {
    if (phones) {
        NSMutableArray *arr = nil;
        if (self.phoneNumbers) {
            arr = [NSMutableArray arrayWithArray:self.phoneNumbers];
        } else {
            arr = [NSMutableArray array];
        }
        for (NSString *phone in phones) {
            CNLabeledValue *value = [CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberiPhone value:[CNPhoneNumber phoneNumberWithStringValue:phone]];
            [arr addObject:value];
        }
        self.phoneNumbers = arr;
    }
}

- (NSArray *)phones {
    NSMutableArray *arr = [NSMutableArray array];
    for (CNLabeledValue *value in self.phoneNumbers) {
        CNPhoneNumber *phoneNumber = value.value;
        [arr addObject:[CYABTool formatPhoneNumber:phoneNumber.stringValue]];
    }
    return arr;
}

- (NSString *)name {
    return [CNContactFormatter stringFromContact:self style:CNContactFormatterStyleFullName];
}
@end
#endif
